﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common.Definition;
using Besture.Model;
using System.Data;

namespace Besture.UI.News
{
    public partial class ActiveList : System.Web.UI.Page
    {
        //Banner图
        public ImageModel _BannerTop { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
            GetBanner();
        }
        public string IsTheEnd(object date)
        {
            string re = "";
            if (!string.IsNullOrEmpty(date + ""))
            {
                DateTime now = DateTime.Now.AddDays(1).Date;
                if (Convert.ToDateTime(date)<now)
                {
                    re = "review-onesre";
                }
            }
            return re;
        }

        public int GetUserCount(string allCount, string hasCount)
        {
            int re = 100;
            if (!string.IsNullOrEmpty(hasCount))
            {
                int h = Convert.ToInt32(hasCount);
                if (h > 0)
                    re = h;
            }
            if (!string.IsNullOrEmpty(allCount))
            {
                int h = Convert.ToInt32(allCount);
                if (h > 0)
                    re = h;
            }
            return re;
        }

        #region 初始化数据
        private void InitData()
        {
            DataTable table = new ActiveNewsDac().GetDataTable(Constants.DICTIONARY_TYPENAME_Active, false);
            if (table != null && table.Rows.Count > 0)
            {
                AspNetPager1.RecordCount = table.Rows.Count;
                var pds = new PagedDataSource
                {
                    AllowPaging = true,
                    DataSource = table.DefaultView,
                    PageSize = AspNetPager1.PageSize,
                    CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1
                };
                rpActivity.DataSource = pds;
                rpActivity.DataBind();
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            InitData();
        }
        #endregion

        #region 获取Banner
        /// <summary>
        /// 获取Banner
        /// </summary>
        public void GetBanner()
        {
            ImageDac imageDac = new ImageDac();
            ImageModel imgModel = imageDac.GetDataTableByCode(Constants.DICTIONARY_CODE_BannerNews, Constants.DICTIONARY_TYPE_IMAGES);
            if (imgModel != null)
                _BannerTop = imgModel;
            else
                _BannerTop = new ImageModel();
        }
        #endregion
    }
}